<!--vue模板-->
<template>
  <div class="user" ref="user"></div>
</template>

<!--vue 组件选项定义-->
<script>
import * as echarts from "echarts";
export default {
  data() {
    return {
      xuser: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
      yuser: [5, 20, 36, 10, 10, 20],
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      let myChart = echarts.init(this.$refs.user);
      //选项对象
      let option = {
        title: {
          text: "ECharts 入门示例",
        },
        tooltip: {},
        xAxis: {
          data: this.xuser,
        },
        yAxis: {},
        series: [
          {
            name: "销量",
            type: "bar",
            data: this.yuser,
          },
        ],
      };
      // 绘制图表
      myChart.setOption(option);
    },
  },
};
</script>

<!--vue样式 scoped当前样式只适用于当前组件-->
<style scoped>
.user {
  width: 500px;
  height: 300px;
  background-color: #ddd;
}
</style>
